home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.02 Feb 90 / Mouse Source / TrackEdit.h < prev    next >
Encoding:
C/C++ Source or Header  |  1989-07-22  |  6.9 KB  |  204 lines  |  [TEXT/KAHL]

  1. /*                                            MouseTrack.h                                        */
  2. /*
  3.  *
  4.  * Copyright © 1989 Martin Minow. All rights reserved.
  5.  *
  6.  * You may incorporate portions of this program in your
  7.  * applications without restriction as long as this
  8.  * copyright notice remains intact and the applications
  9.  * are not sold for profit and this source is not
  10.  * redistributed for profit.
  11.  *
  12.  * Private macros and functions are prefixed by _Track_
  13.  */
  14. #ifndef    _MouseTrackHdr_
  15. #define    _MouseTrackHdr_
  16. #include <ScriptMgr.h>
  17. /*
  18.  * Compiler-independent datatype definitions.
  19.  */
  20. typedef short                        INTEGER;
  21. typedef unsigned short    CHAR;
  22. typedef long                        LONGINT;
  23. typedef unsigned long        DOT;
  24.  
  25. /*
  26.  * All of the information the program needs to process
  27.  * text is contained in the TrackRecord structure.
  28.  * Note that all callback procedures should be declared
  29.  * pascal <type> function.
  30.  */
  31.  typedef struct {
  32.      LONGINT        topPixel;            /* Top line in viewRect                */
  33.      LONGINT        leftPixel;        /* Leftmost pixel in ViewRect    */
  34.      INTEGER        lineWidth;        /* Document's pixel width            */
  35.     Rect            viewRect;            /* View (clip) rectangle            */
  36.     INTEGER        lineHeight;        /* For line spacing                        */
  37.     INTEGER        fontAscent;        /* Caret/highlight position        */
  38.     INTEGER        fontDescent;    /* For caret positioning            */
  39.     LONGINT        selRow;                /* For caret positioning            */
  40.     DOT                selStart;            /* Start of selection range        */
  41.     DOT                selEnd;                /* End of selection range            */
  42.     ProcPtr        wordBreak;        /* At a word boundary?                */
  43.     ProcPtr        clikLoop;            /* Called from TrackClick            */
  44.     LONGINT        clickTime;        /* Mouse-up time                            */
  45.     DOT                clickLoc;            /* Mouse-up position                    */
  46.     LONGINT        caretTime;        /* Used to flash the caret        */
  47.     INTEGER        just;                    /* Justification flags                */
  48.     LONGINT        textLength;        /* Total text length                    */
  49.     Handle        hText;                /* Text to be selected                */
  50.     INTEGER        crOnly;                /* If < 0, newline at Return    */
  51.     INTEGER        txFont;                /* Text font number                        */
  52.     Style            txFace;                /* Character style                        */
  53.     INTEGER        txMode;                /* Pen mode                                        */
  54.     INTEGER        txSize;                /* Font size                                    */
  55.     GrafPtr        inPort;                /* Output grafPort                        */
  56.     INTEGER        flags;                /* Internal flags                            */
  57.     ProcPtr        highHook;            /* User hilite  procedure            */
  58.     ProcPtr        caretHook;        /* User draw caret procedure    */
  59.     LONGINT        refCon;                /* For user program use                */
  60.     LONGINT        nLines;                /* Number of lines of text        */
  61.     DOT                lineStarts[1];/* Start of each line                    */
  62. } TrackRecord, *TrackPtr, **TrackHandle;
  63.  
  64. /*
  65.  * just contains the following values (identical to
  66.  * TextEdit).
  67.  */
  68. enum {
  69.     trackJustLeft = 0,
  70.     trackJustCenter = 1,
  71.     trackJustRight = -1
  72. };
  73.  
  74. /*
  75.  * flags contains the following bit-encoded values.
  76.  */
  77. #define    _Track_has_script_manager        0x0001
  78. #define    _Track_use_script_manager        0x0002
  79. #define    _Track_use_smart_cut_paste    0x0004
  80. #define    _Track_is_active                        0x0008
  81. #define    _Track_caret_visible                0x0010
  82. #define    _Track_do_autoscroll                0x0020
  83.  
  84. /*
  85.  * When any Track routine is called, it calls _Track_lock
  86.  * to record the current state of the TrackRecord in this
  87.  * structure.  On exit, _Track_unlock restores the
  88.  * original state.
  89.  */
  90. typedef struct {
  91.     TrackHandle    track_handle;    /* The track handle itself    */
  92.     INTEGER        oldHState;        /* Handle locked flag                    */
  93.     GrafPtr        oldPort;            /* Caller's GrafPort                    */
  94.     RgnHandle    oldClip;            /* Previous clip region                */
  95.     INTEGER        oldFont;            /* Previous font                            */
  96.     Style            oldFace;            /* Previous text face                    */
  97.     INTEGER        oldMode;            /* Previous drawing mode            */
  98.     INTEGER        oldSize;            /* Previous text size                    */
  99. } _Track_state;
  100.  
  101. /*
  102.  * These macros access the private flags in TrackRecord.
  103.  */
  104. #define _Track_set(p, x)                 ((p)->flags |= (x))
  105. #define _Track_clear(p, x)             ((p)->flags &= ~(x))
  106. #define _Track_flip(p, x)                ((p)->flags ^= (x))
  107. #define _Track_is_set(p, x)            (((p)->flags & (x)) != 0)
  108.  
  109. /*
  110.  * "desired state" parameter for _Track_caret()
  111.  */
  112. #define    _Track_caret_on            0
  113. #define    _Track_caret_off        1
  114. #define _Track_caret_invert    2
  115.  
  116. /*
  117.  * This structure records both ends of a word.
  118.  */
  119. typedef struct {
  120.     DOT            start;                        /* Start of word                        */
  121.     DOT            end;                            /* End of word                            */
  122. } _Track_Loc;
  123.  
  124. /*
  125.  * User-callable prototypes
  126.  */
  127. void            TrackActivate(TrackHandle);
  128. void            TrackAutoView(Boolean, TrackHandle);
  129. void            TrackCalText(TrackHandle);
  130. void            TrackClick(Point, Boolean, TrackHandle);
  131. void            TrackCopy(TrackHandle);
  132. void            TrackCut(TrackHandle);
  133. void            TrackDeactivate(TrackHandle);
  134. void            TrackDelete(TrackHandle);
  135. void            TrackDispose(TrackHandle);
  136. OSErr            TrackFromScrap(void);
  137. LONGINT        TrackGetHeight(LONGINT, LONGINT, TrackHandle);
  138. DOT                TrackGetOffset(Point, TrackHandle);
  139. void            TrackGetPoint(
  140.                         DOT, TrackHandle, LONGINT *, LONGINT *);
  141. LONGINT        TrackGetScrapLen(void);
  142. #define        TrackGetSelectionLength(track_handle) \
  143.     ((*track_handle)->selEnd - (*track_handle)->selStart)
  144. Handle        TrackGetText(TrackHandle);
  145. void            TrackIdle(TrackHandle);
  146. void            TrackInit(void);
  147. void            TrackInsert(Ptr, LONGINT, TrackHandle);
  148. void            TrackKey(CHAR, TrackHandle);
  149. #define        TrackLength(track_handle) \
  150.     ((*track_handle)->textLength)
  151. TrackHandle    TrackNew(INTEGER, Rect *);
  152. void            TrackPaste(TrackHandle);
  153. void            TrackPinScroll(LONGINT, LONGINT, TrackHandle);
  154. Handle        TrackScrapHandle(void);
  155. void            TrackScroll(LONGINT, LONGINT, TrackHandle);
  156. void            TrackSelView(TrackHandle);
  157. #define        TrackSetClikLoop(func, track_handle) \
  158.     ((*track_handle)->clikLoop = func)
  159. void            TrackSetJust(INTEGER, TrackHandle);
  160. void            TrackSetScrapLen(LONGINT);
  161. void            TrackSetSelect(DOT, DOT, TrackHandle);
  162. void            TrackSetText(Ptr, LONGINT, TrackHandle);
  163. #define        TrackSetWordBreak(func, h) \
  164.     ((*track_handle)->wordBreak = func)
  165. OSErr            TrackToScrap(void);
  166. void            TrackUpdate(Rect *, TrackHandle);
  167.  
  168. /*
  169.  * These functions are called internally by the Track
  170.  * library.  They are not be called by user programs.
  171.  * Note: the TrackRecord is locked when these functions
  172.  * are called.  A few functions temporarily unlock the
  173.  * TrackRecord: they return a new TrackPtr value.
  174.  */
  175. void            _Track_autoscroll(TrackPtr, Point *);
  176. void            _Track_caret(TrackPtr, INTEGER);
  177. void            _Track_do_clear(TrackHandle, Boolean, Boolean);
  178. void            _Track_do_insert(TrackPtr, long, Ptr, long);
  179. void            _Track_do_paste(TrackHandle);
  180. void            _Track_do_scroll(TrackPtr, LONGINT, LONGINT);
  181. void            _Track_do_update(TrackPtr, Rect *);
  182. LONGINT        _Track_dot_to_bol(TrackPtr, LONGINT);
  183. LONGINT        _Track_dot_to_col(TrackPtr, DOT);
  184. LONGINT        _Track_dot_to_eol(TrackPtr, LONGINT);
  185. LONGINT        _Track_h_origin(TrackPtr, LONGINT);
  186. void            _Track_hilite(TrackPtr, DOT, DOT);
  187. void            _Track_invert_caret(TrackPtr);
  188. Boolean        _Track_is_white(TrackPtr, char *, DOT);
  189. TrackPtr    _Track_lock(TrackHandle, _Track_state *);
  190. DOT                _Track_mouse_to_dot(TrackPtr, Point);
  191. LONGINT        _Track_pixel_row(TrackPtr, INTEGER);
  192. TrackPtr    _Track_rebuild(TrackHandle, DOT);
  193. LONGINT        _Track_row(TrackPtr, DOT);
  194. LONGINT        _Track_row_pixel(TrackPtr, LONGINT);
  195. void            _Track_unlock(_Track_state *);
  196. void            _Track_word(TrackPtr, Point, _Track_Loc *);
  197.  
  198. /*
  199.  * Track library private data.
  200.  */
  201. extern Handle        TrackScrpHandle;        /* Track Scrap            */
  202. extern LONGINT    TrackScrpLength;        /* Scrap length            */
  203.  
  204. #endif